package com.u.social.search.service;

import com.u.social.search.model.ArticleDTO;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @program: u-social
 * @description: 重排
 * @author: Alex Wu
 * @createDate: 2025-04-11 15:08
 **/

@Service
public class RoughRankingService {

    /**
     * 粗排-根据文本相关性，质量分，转化率加权权重打分
     * @param recalls
     * @return
     */
    public List<ArticleDTO> roughSortByWeightRule(List<ArticleDTO> recalls) {
        System.out.println("粗排");
        for (ArticleDTO articleDTO : recalls) {
            // 计算权重
            float recallScore = articleDTO.getRecallScore();
            // 计算权重
            float weight = recallScore * 0.5f;
            articleDTO.setRecallScore(weight);
        }
        // 按 recallScore 降序排序
        recalls.sort((a, b) -> Float.compare(b.getRecallScore(), a.getRecallScore()));
        return recalls.size() > 200 ? recalls.subList(0, 200) : recalls;
    }
}
